package first

class PersonController {

    static layout = "main"
    def index() { }

    //перенаправляет на gsp
    def createPerson() {
    }

    def createPersonAction() {

        def address = new Address(params)
        def person = new Person(params)

//        if (person.validate()){
//            println(person.errors)
//            person.address = address
//        person.save(validate: false)
//        redirect action: "show"
//
//    }  else {
//        flash.message = "Error creating person"
//
//    //    render view: "createPerson", model: [person: person]
//    }
        person.address = address
        person.save()
    redirect action: "show"
}




    def show() {
        List<Person> persons = Person.findAll("from Person", [offset: (params.offset ?: 0) as int, max: 10])
        [persons: persons, personCount: Person.count()]
    }


    def delete (){
        if (params.id){
            Person person = Person.get(params.id as long)
            person.delete()
        }

        redirect action: "show"
    }
}
